package com.qf;

import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * @author Ypl
 * @version V1.0
 * @Project OctoberAndNovember
 * @Package com.qf
 * @Description:
 * @Date 2022/11/2 10:38
 */
@SpringBootApplication
@EnableEurekaClient //开启eureka客户端注册
@EnableFeignClients(basePackages = "com.qf.feign")
@EnableCircuitBreaker
@EnableHystrixDashboard //断路器面板
@ServletComponentScan(basePackages ="com.qf.servlet")
public class OrderApplication {

    //将对象存入容器中，自动注入时使用
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    //在容器中添加  负载均衡策略（随机轮询）
    @Bean
    public RandomRule randomRule(){
        return new RandomRule();
    }

    public static void main(String[] args) {
        SpringApplication.run(OrderApplication.class, args);
    }
}
